<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.util.List" import="com.itheima.domain.Book" pageEncoding="UTF-8"%>
<%@ page import="com.itheima.domain.User" %>
<html>
<head>
    <title>借阅列表</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-4">
    <h2 class="mb-4">📚 所有借阅</h2>
    <table class="table table-bordered table-hover">
        <thead class="table-dark">
        <tr>
            <th>ID</th>
            <th>书名</th>
            <th>借阅人</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>

        <%
            @SuppressWarnings("unchecked")
            List<Book> books = (List<Book>) request.getAttribute("bookList");
            request.getSession().getAttribute("user");
            for (Book book : books) {
        %>
        <tr>
            <td><%= book.getId() %></td>
            <td><%= book.getBookName() %></td>
            <td><%= book.getPrice() %></td>
            <td>
                <img src="book/image/<%= book.getId() %>" width="100" height="150" alt=""/>
            </td>
            <td>
                <form action="borrow" method="post" style="display:inline;">
                    <input type="hidden" name="bookId" value="<%= book.getId() %>">
                    <input type="hidden" name="userId" value="<%= ((User)session.getAttribute("user")).getId() %>">
                    <button type="submit" class="btn btn-danger">归还</button>
                </form>

            </td>
            <td>
                <div class="alert alert-info">${msg}</div>
            </td>
        </tr>
        <%
            }
        %>
        </tbody>
        <a href="index.jsp"><i>返回主页</i></a>
    </table>
</div>
</body>
</html>
